<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php  echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js","jquery.pagination.js","jquery.tablesorter.min.js","jquery.tablednd.js","datepicker.js")); ?>
<?php
echo $this->Html->css('datepicker');
?>
<script type="text/javascript">
// <![CDATA[
function pad(value, length) {
        length = length || 2;
        return "0000".substr(0,length - Math.min(String(value).length, length)) + value;
};
// ]]>
</script>
</head>
<body>
<div id="result">
<div class="div_header1">Edit Q-Admin</div>
<form method="post" id="edit_admin" action="<?php echo Configure::read('base_url')."users/edit";?>">
<table cellspacing="0" id="mytable" style="float: left;">
          <tbody>
    <tr>
    <td colspan="2">
    <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="float: left;">
    <tr>
    <td width="266" align="right">
    First Name*
    </td>
    <td width="247" align="left">
        <?php
          echo $this->Form->hidden('User.id');
        echo $this->Form->input('User.first_name',array('label'=>false,'div'=>false,'class'=>'required'));
        ?>
    </td>
    <td width="266" align="right">
   Last Name*
    </td>
    <td width="247" align="left">
        <?php
        echo $this->Form->input('User.last_name',array('label'=>false,'div'=>false,'class'=>'required'));
        ?>
    </td>
    </tr>
     <tr >
    <td width="266" align="right">
    Street Address*
    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.address',array('label'=>false,'div'=>false,'class'=>'required medium'));
        ?>
    </td>

    </tr>
     <tr >
    <td width="266" >

    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.address2',array('label'=>false,'div'=>false,'class'=>'medium'));
        ?>
    </td>

    </tr>
     <tr >
    <td width="266" align="right">
   City*
    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.city',array('label'=>false,'div'=>false,'class'=>'required'));
        ?>
    </td>

    </tr>
    <tr>
    <td width="266" align="right">
    State*
    </td>
    <td width="247" align="left">
        <?php
        echo $this->Form->input('User.state_id',array('label'=>false,'div'=>false,'class'=>'required','empty'=>'Select'));
        ?>
    </td>
    <td width="266" align="right">
   Zip*
    </td>
    <td width="247" align="left">
        <?php
        echo $this->Form->input('User.zip',array('label'=>false,'div'=>false,'class'=>'required'));
        ?>
    </td>
    </tr>
     <tr >
    <td width="266" align="right">
   Country*
    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.country_id',array('label'=>false,'div'=>false,'class'=>'required','empty'=>'Select'));
        ?>
    </td>

    </tr>
 <tr >
    <td width="266" align="right">
Primary Phone # *
    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.primary_phone',array('label'=>false,'div'=>false,'maxlength'=>"3",'size'=>'4','style'=>'float:left;margin-right:10px;'));
         echo $this->Form->input('User.phone2',array('label'=>false,'div'=>false,'maxlength'=>"4",'size'=>'5','style'=>'float:left;margin-right:10px;'));
          echo $this->Form->input('User.phone3',array('label'=>false,'div'=>false,'maxlength'=>"3",'size'=>'4','class'=>'required'));
        ?>
    </td>

    </tr>
    <tr>
    <td width="266" align="right">
   Email*
    </td>
    <td width="247" align="left">
        <?php
        echo $this->Form->input('User.email',array('id'=>'email','label'=>false,
            'div'=>false,'class'=>'required email'));
        ?>
    </td>
    <td width="266" align="right">
  Confirm Email*
    </td>
    <td width="247" align="left">
        <?php
        echo $this->Form->input('cemail',array('label'=>false,'name'=>'cemail',
            'div'=>false,'size'=>'19','value'=>$this->data['User']['email']));
        ?>
    </td>
   </tr>
        <tr >
    <td width="266" align="right">
   User Id*
    </td>
    <td width="247" colspan="3">
    <input type="text" disabled name="nothing"
           value="<?php echo $this->data['User']['username']; ?>"/>
        <?php
        /*echo $this->Form->input('User.username',array('label'=>false,'div'=>false,
            'name'=>'username','id'=>'username'));*/
        ?>
    </td>

    </tr>
    <tr>
    <td width="266" align="right">
   Password*
    </td>
    <td width="247">
        <?php
        echo $this->Form->input('password',array('label'=>false,'div'=>false,
            'name'=>'password','id'=>'password','type'=>'password'));
        ?>
    </td>
    <td width="266" align="right">
  Confirm Password*
    </td>
    <td width="247">
        <?php
        echo $this->Form->input('cpassword',array('label'=>false,'div'=>false,
            'name'=>'cpassword','id'=>'cpassword','type'=>'password','size'=>'19'));
        ?>
    </td>
    </tr>
     <tr >
    <td width="266" align="right">
   Secret Question*
    </td>
    <td width="247" colspan="3" align="left">
        <?php
       echo $this->Form->input('User.secretquestion_id',array('empty'=>'Select your Secret question','div'=>false,'label'=>false,'class'=>'required','style'=>"width:195px"));
        ?>
    </td>
    </tr>
    <tr >
    <td width="266" align="right">
   Your Secret Answer*
    </td>
    <td width="247" colspan="3" align="left">
        <?php
        echo $this->Form->input('User.ques_ans',array('label'=>false,'value'=>base64_decode($this->data['User']['ques_ans']),'div'=>false,'class'=>'required'));
        ?>
    </td>

    </tr>
    <tr >
    <td width="266" align="right">
   Date of Birth*
    </td>
    <td width="247" colspan="3" align="left">
       <input type="text" readonly class="w16em required" id="selectDate"
              name="data[User][dateofbirth]"
              value="<?php echo $this->data['User']['dateofbirth']; ?>"/>
        <?php
        /*echo $this->Form->input('User.dateofbirth',array('label'=>false,'div'=>false,
            'class'=>'required','minYear'=>1900));*/
        ?>
<script type="text/javascript">
     var today     = new Date(),
            // low range, 35 days before today's date
            //rangeLow  = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 35),
			// low range, form today's date
            rangeLow  = new Date(today.getFullYear()-150, today.getMonth(), today.getDate()),
            // high range, one year after today's date
            rangeHigh = new Date(today.getFullYear()-18, today.getMonth(), today.getDate())

        var opts = {
                formElements:{"selectDate":"Y-ds-m-ds-d"},
                showWeeks:true,
                statusFormat:"l-cc-sp-d-sp-F-sp-Y",
                // Set some dynamically calculated ranges
                rangeLow:rangeLow.getFullYear() + "" + pad(rangeLow.getMonth()+1) + pad(rangeLow.getDate()),
                rangeHigh:rangeHigh.getFullYear() + "" + pad(rangeHigh.getMonth()+1) + pad(rangeHigh.getDate())

        };
        if(jQuery("#fd-selectDate").html()!=null){
           jQuery('#fd-selectDate').remove();
        }
        datePickerController.createDatePicker(opts);
     // <![CDATA[
      /* var opts = {
                formElements:{"selectDate":"Y-ds-m-ds-d"},
                showWeeks:true,
                // Show a status bar and use the format "l-cc-sp-d-sp-F-sp-Y" (e.g. Friday, 25 September 2009)
                statusFormat:"l-cc-sp-d-sp-F-sp-Y"
        };
        //alert(jQuery("#fd-selectDate").html());
        if(jQuery("#fd-selectDate").html()!=null){
           jQuery('#fd-selectDate').remove();
        }
        datePickerController.createDatePicker(opts);*/
// ]]>
</script>
    </td>

    </tr>
    <tr >
    <td width="266" align="right">
   Commission Rate*
    </td>
    <td width="247" colspan="3" align="left">
         <input type="hidden" name="data[User][brandsid]" id="hdID" value=""/>
         <input type="hidden" name="data[User][styleid]" id="hdID2" value=""/>
          <input type="hidden" name="data[User][conditionsid]" id="hdID3" value=""/>
        <?php
        echo $this->Form->input('User.commission',array('label'=>false,'div'=>false,'class'=>'required number','size'=>'8','style'=>'float:left;margin-right:10px;'));
        ?>%
    </td>

    </tr>
     <tr >
    <td width="266" colspan="4">
   Permissions*
    </td>
    </tr>
    <tr >
    <td width="266" colspan="4">
   <div> 
       <a href="#?w=500" rel="popup_name" class="poplight">
           Click here to select the brands for this Q-Admin</a>
   </div>
       </td>
    </tr>
    <tr>
    <td width="144">

    </td>
    <td width="347"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="button" id="button" value="Update" /></td>
    </tr>
    </table>
    </td>
    </tr>
        </tbody></table>
</form>
</div>
    <div id="popup_name" class="popup_block">
        <?php  echo $html->script(array("jquery.min.js")); ?>
        <script type="text/javascript">

            jQuery(document).ready(function(){

                //Check all
		$("#select_brand_all").click(function()
			{
				var checked_status = this.checked;
				$("input[id=global_brand]").each(function()
				{
					this.checked = checked_status;
				});
			});
			$("#select_style_all").click(function()
			{
				var checked_status = this.checked;
				$("input[id=global_style]").each(function()
				{
					this.checked = checked_status;
				});
			});
			$("#select_condition_all").click(function()
			{
				var checked_status = this.checked;
				$("input[id=global_condition]").each(function()
				{
					this.checked = checked_status;
				});
			});

        /*$("#user_linksb").click(function()
        {
        $("#suggest_global_content").toggle("slow");
        });*/
 jQuery(":button#canb").click(function () {
     jQuery('#fade , .popup_block').fadeOut(function() {
            jQuery('#fade, a.close').remove();  //fade them both out
        });
        return false;
 });

                jQuery(":button#addb").click(function () {
                   // alert('hello');
                    //hdIDValue=jQuery("input[name=test]").val();
                    hdIDValue=jQuery("form#brand").serialize();
                     jQuery.ajax({
                            url : baseurl+"users/brandaccess/",
                            data:hdIDValue,
                            dataType: 'json',
                            type:'POST',
                            success : function (data) {
                                   // alert(data.hdIDValue);
                                    window.parent.document.getElementById('hdID').value=data.hdIDValue;
                                    window.parent.document.getElementById('hdID2').value=data.hdIDValuest;
                                    window.parent.document.getElementById('hdID3').value=data.hdIDValuecon;
                                     jQuery('#fade , .popup_block').fadeOut(function() {
                                        jQuery('#fade, a.close').remove();  //fade them both out
                                      });
                                       return false;
                            }
                        });

                });


            });
        </script>

       <form method="post" id="brand" action="javascript:void(0);">
           <table width="100%" cellspacing="0"  id="suggest_global_content" style="display:block;">
  <tr><td colspan="2"><b>Global Brands</b></td></tr>
  <tr>
    <td width="30"><input type="checkbox" id="select_brand_all"></td>
    <td width="97%">Select all</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<?php $i=0;foreach($this->data['global_brand'] as $brand):
		$class = null;
		if ($i++ % 2 == 0)
		$class = ' class="alt"';
                $checked = '';
		
		foreach($globales as $global):
                    
			if($global['BrandPermission']['brand_id'] == $brand['Brand']['id'])
				$checked = ' checked="checked"';
			endforeach;
		

	?>
      <tr>
        <td width="30" <?php echo $class;?>><input type="checkbox" <?php echo $checked;?> class="<?php echo $this->data['User']['id'];?>"  name="data[global_brand][]"  onClick="return branchk(this,<?php echo $this->data['User']['id'];?>);" id="global_brand" value="<?php echo $brand['Brand']['id'];?>" /></td>
        <td <?php echo $class;?>><?php echo $brand['Brand']['brand_description'];?><span id="<?php echo $brand['Brand']['id'];?>" style="color:red; margin-left:5px;"></span></td>
      </tr>
    <?php endforeach;?>
    </table></td>
  </tr>
  <tr><td colspan="2"><b>Global Style</b></td></tr>
  <tr>
    <td width="30"><input type="checkbox" id="select_style_all"></td>
    <td width="97%">Select all</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<?php $i=0;foreach($this->data['global_style'] as $brand):
		$class = null;
		if ($i++ % 2 == 0)
		$class = ' class="alt"';
                $checked = '';
		foreach($globales as $global):
			if($global['BrandPermission']['brand_id'] == $brand['Brand']['id'])
				$checked = ' checked="checked"';
			endforeach;
		//}
	?>
      <tr>
        <td width="30" <?php echo $class;?>><input type="checkbox" <?php echo $checked;?>  class="<?php echo $this->data['User']['id'];?>"   onClick="return branchk(this,<?php echo $this->data['User']['id'];?>);" name="data[global_style][]" id="global_style" value="<?php echo $brand['Brand']['id'];?>" /></td>
        <td <?php echo $class;?>><?php echo $brand['Brand']['brand_description'];?><span id="<?php echo $brand['Brand']['id'];?>" style="color:red; margin-left:5px;"></span></td>
      </tr>
    <?php endforeach;?>
    </table></td>
  </tr>
 <tr><td colspan="2"><b>Global Condition</b></td></tr>
  <tr>
    <td width="30"><input type="checkbox" id="select_condition_all"></td>
    <td width="97%">Select all</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<?php $i=0;foreach($this->data['global_condition'] as $brand):
		$class = null;
		if ($i++ % 2 == 0)
		$class = ' class="alt"';
                $checked = '';
		foreach($globales as $global):
			if($global['BrandPermission']['brand_id'] == $brand['Brand']['id'])
				$checked = ' checked="checked"';
			endforeach;
		//}
	?>
      <tr>
        <td width="30" <?php echo $class;?>><input type="checkbox" <?php echo $checked;?> name="data[global_condition][]"   onClick="return branchk(this,<?php echo $this->data['User']['id'];?>);" class="<?php echo $this->data['User']['id'];?>" id="global_condition" value="<?php echo $brand['Brand']['id'];?>" /></td>
        <td <?php echo $class;?>><?php echo $brand['Brand']['brand_description'];?><span id="<?php echo $brand['Brand']['id'];?>" style="color:red; margin-left:5px;"></span></td>
      </tr>
    <?php endforeach;?>
    </table></td>
  </tr>

</table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="30" align="right"><input type="button" name="Update" value="Update" id="addb"/></td>
        <td width="30"> <input id="canb" type="button" name="cancel" value="Cancel" /></td>
      </tr>

          </table>

                   </form>
            </div>

 <script type="text/javascript">
 jQuery(document).ready(function(){

  //Check all
		$("#select_brand_all").click(function()
			{
				var checked_status = this.checked;

				jQuery("input[id=global_brand]").each(function()
				{
                                   this.checked = checked_status;
                                    var brandid= jQuery(this).val();
                                    var userid= jQuery(this).attr('class');
                                    if(jQuery(this).attr('id')=='global_brand')
                                     var style='Global Brand';
                                 if(jQuery(this).attr('id')=='global_style')
                                     var style='Global Style';
                                 if(jQuery(this).attr('id')=='global_condition')
                                     var style='Global Condition';
                                    if(checked_status==true){



                                           jQuery.ajax({
                                            url : "<?php echo $html->url(array('controller'=>'users','action'=>'brandcheck'));?>/"+brandid+'/'+style+'/'+userid,
                                            success : function (html) {
                                           jQuery("#"+brandid).html(html);
                                            }
                                            });

                                    }else{
                                         jQuery("#"+brandid).html("");
                                    }


				});
			});
			$("#select_style_all").click(function()
			{
				var checked_status = this.checked;

				jQuery("input[id=global_style]").each(function()
				{
                                   this.checked = checked_status;
                                    var brandid= jQuery(this).val();
                                    var userid= jQuery(this).attr('class');
                                    if(jQuery(this).attr('id')=='global_brand')
                                     var style='Global Brand';
                                 if(jQuery(this).attr('id')=='global_style')
                                     var style='Global Style';
                                 if(jQuery(this).attr('id')=='global_condition')
                                     var style='Global Condition';
                                    if(checked_status==true){



                                           jQuery.ajax({
                                            url : "<?php echo $html->url(array('controller'=>'users','action'=>'brandcheck'));?>/"+brandid+'/'+style+'/'+userid,
                                            success : function (html) {
                                           jQuery("#"+brandid).html(html);
                                            }
                                            });

                                    }else{
                                        jQuery("#"+brandid).html("");
                                    }


				});
			});
			$("#select_condition_all").click(function()
			{
				 var checked_status = this.checked;
                                
				jQuery("input[id=global_condition]").each(function()
				{
                                   this.checked = checked_status;
                                    var brandid= jQuery(this).val();
                                    var userid= jQuery(this).attr('class');
                                    
                                    if(jQuery(this).attr('id')=='global_brand')
                                     var style='Global Brand';
                                 if(jQuery(this).attr('id')=='global_style')
                                     var style='Global Style';
                                 if(jQuery(this).attr('id')=='global_condition')
                                     var style='Global Condition';
                                    if(checked_status==true){



                                           jQuery.ajax({
                                            url : "<?php echo $html->url(array('controller'=>'users','action'=>'brandcheck'));?>/"+brandid+'/'+style+'/'+userid,
                                            success : function (html) {
                                           jQuery("#"+brandid).html(html);
                                            }
                                            });

                                    }else{
                                        jQuery("#"+brandid).html("");
                                    }


				});
			});

        $("#user_linksb").click(function()
        {
        $("#suggest_global_content").toggle("slow");
        });

 
 jQuery("#category_table").tablesorter({headers: { 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}});

// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="<?php echo Configure::read('base_url');?>img/loading.gif" alt="loading..." /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});

		var v = jQuery("#edit_admin").validate({

                 rules: {
                    email:{
                        'required':true,
                        'email':true
                          },
                    cemail: {
                    required: true,
                    equalTo: '#email'
                    },
                    cpassword: {
                     equalTo: '#password'
                    }
                   },
                   
      submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});


                 });


 </script>
<script type="text/javascript">
function branchk(param,uid){
             var brandid= jQuery(param).val();
//             alert(brandid);
//             alert(uid);
//             die();
             if(jQuery(param).attr('id')=='global_brand')
             var style='Global Brand';
         if(jQuery(param).attr('id')=='global_style')
             var style='Global Style';
         if(jQuery(param).attr('id')=='global_condition')
             var style='Global Condition';
             if(param.checked==true){
               jQuery.ajax({
                url : "<?php echo $html->url(array('controller'=>'users','action'=>'brandcheck'));?>/"+brandid+'/'+style+'/'+uid,
                success : function (html) {
               jQuery("#"+brandid).html(html);
                }
                });
                }else{
                 jQuery("#"+brandid).html("");
                   
                }

            }
</script>
</body>
</html>
<style type="text/css">

    #fade { /*--Transparent background layer--*/
	display: none; /*--hidden by default--*/
	
	position: fixed; left: 0; top: 0;
	width: 100%; height: 100%;

}
.popup_block{
	display: none; /*--hidden by default--*/
	background: #fff;
	padding: 20px;
	border: 0px solid #ddd;
	float: left;
	font-size: 1.2em;
	position: fixed;
	top: 50%; left: 50%;

	/*--CSS3 Box Shadows--*/
	-webkit-box-shadow: 0px 0px 20px #000;
	-moz-box-shadow: 0px 0px 20px #000;
	box-shadow: 0px 0px 20px #000;
	/*--CSS3 Rounded Corners--*/
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;
        max-height: 400px;
        overflow: auto;
        
}
img.btn_close {
    float: left;
    margin: -25px 0px 0 -25px;
    border: 0px;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
	position: absolute;
}
*html .popup_block {
	position: absolute;
}

</style>
<script type="text/javascript">
jQuery(document).ready(function() {
	//When you click on a link with class of poplight and the href starts with a #
jQuery('a.poplight[href^=#]').click(function() {
    var popID = jQuery(this).attr('rel'); //Get Popup Name
    var popURL = jQuery(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    jQuery('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="../img/close-bg.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = (jQuery('#' + popID).height() + 80) / 2;
    var popMargLeft = (jQuery('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    jQuery('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    jQuery('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    jQuery('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies

    return false;
});

//Close Popups and Fade Layer
jQuery('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    jQuery('#fade , .popup_block').fadeOut(function() {
        jQuery('#fade, a.close').remove();  //fade them both out
    });
    return false;
});

});
</script>